<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>location.host 示例</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; }
        #info { background: #f4f4f4; padding: 15px; border-left: 5px solid #007acc; }
    </style>
</head>
<body>

<h2>location.host 实时演示</h2>
<div id="info"></div>

<script>
    // 把 location 相关字段都打印出来，方便对比
    const html = `
        <strong>当前地址：</strong>${location.href}<br>
        <strong>location.host：</strong>${location.host}<br>
        <strong>location.hostname：</strong>${location.hostname}<br>
        <strong>location.port：</strong>${location.port}<br>
        <strong>location.protocol：</strong>${location.protocol}<br>
    `;
    document.getElementById('info').innerHTML = html;

    // 再拼一个 WebSocket 地址给你看
    const wsUrl = "ws://" + location.host + "/room";
    console.log("自动拼出来的 WebSocket 地址是：", wsUrl);
</script>

</body>
</html>